
package com.comtop.lcam.fwms.managementkey.socket;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * soket监听服务
 * 
 * @author 李锋
 * @version 2018-11-20 李锋
 * @since 1.0
 */
public class EslcsSocketService implements Runnable {
    
    /** 异常输出 */
    private static final Logger LOGGER = LoggerFactory.getLogger(EslcsSocketService.class);
    
    /**
     * soket监听
     */
    public static void soketListener() {
        EventLoopGroup bossGroup = new NioEventLoopGroup();
        EventLoopGroup workerGroup = new NioEventLoopGroup();
        int port = 8523;
        try {
            LOGGER.error("======Netty port:" + port + "start=======");
            ServerBootstrap bootstrap = new ServerBootstrap();
            bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new EslcsSocketChannel());
            ChannelFuture channelFuture = bootstrap.bind(port).sync();
            channelFuture.channel().closeFuture().sync();
        } catch (Exception e) {
            LOGGER.error("======Exception Netty port :" + port + "start========" + e.getMessage());
        } finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }
    }
    
    /**
     * @see java.lang.Runnable#run()
     */
    @Override
    public void run() {
        EslcsSocketService.soketListener();
    }
    
}
